package com.glory.brepda.adapter;

import android.view.View;
import android.widget.CheckBox;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.brepda.R;
import com.glory.brepda.entity.BinInfoEntity;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * FileName: DataBinListAdapter
 * Author: XJH
 * Date: 2020/6/15 14:32
 * Description:
 * History:
 */
public class DataBinListAdapter extends BaseQuickAdapter<BinInfoEntity.BinInfo,BaseViewHolder> {
    private List<BinInfoEntity.BinInfo> mData;
    private boolean mTest;

    public DataBinListAdapter(@Nullable List<BinInfoEntity.BinInfo> data,boolean isTest) {
        super(R.layout.item_ft_data_bin,data);
        mData = new ArrayList<>();
        mTest = isTest;
    }


    @Override
    protected void convert(BaseViewHolder helper, BinInfoEntity.BinInfo item) {
        helper.setText(R.id.tvBinName,item.getBINNO());
        CheckBox checkBox = helper.getView(R.id.checkbox);
        checkBox.setVisibility(mTest ? View.VISIBLE : View.GONE);
        if (mTest){
            checkBox.setChecked(true);
            mData.add(item);
        }else {
            checkBox.setChecked(item.isChecked());
        }
        checkBox.setTag(helper.getAdapterPosition());
        checkBox.setOnClickListener(v -> {
            boolean isChecked = ((CheckBox) v).isChecked();
            if (isChecked) {
                mData.add(item);
            } else {
                mData.remove(item);
            }
        });

    }

    public List<BinInfoEntity.BinInfo>  getItemWork(){
        return mData;
    }
}
